package com.maltys.greedy;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/lemonade-change/">柠檬水找零</a>
 */
public class LemonadeChange {
    public boolean lemonadeChange(int[] bills) {
        int[] cnt = new int[21];
        for (int bill : bills) {
            if (bill == 5) {
                cnt[bill]++;
            } else if (bill == 20 && cnt[10] > 0 && cnt[5] > 0) {
                cnt[bill]++;
                cnt[10]--;
                cnt[5]--;
            } else if (bill == 20 && cnt[5] > 2) {
                cnt[bill]++;
                cnt[5] -= 3;
            } else if (bill == 10 && cnt[5] > 0) {
                cnt[bill]++;
                cnt[5]--;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        LemonadeChange lemonadeChange = new LemonadeChange();
        boolean change = lemonadeChange.lemonadeChange(new int[]{5, 5, 5, 10, 20});
        System.out.println(change);
    }
}
